﻿using Newtonsoft.Json;
using Restaurant.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Restaurant.Client.Framework.Extension
{
    public static class OperationResultEx
    {
        /// <summary>
        /// 获取AppendData 实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="operationResult"></param>
        /// <returns></returns>
        public static T GetAppData<T>(this OperationResult operationResult)
        {
            try
            {
                return JsonConvert.DeserializeObject<T>(operationResult.AppendData.ToString());
            }
            catch (Exception)
            {

                return default;
            }
        }

        /// <summary>
        /// 获取AppendData List<实体>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="operationResult"></param>
        /// <returns></returns>
        public static Tuple<IEnumerable<T>, int> GetListAppData<T>(this OperationResult operationResult)
        {
            try
            {
                return JsonConvert.DeserializeObject<Tuple<IEnumerable<T>, int>>(operationResult.AppendData.ToString());
            }
            catch (Exception)
            {

                return null;
            }
        }

    }
}
